﻿using LeSoft.Application.Bussiness;
using LeSoft.Application.Cache;
using LeSoft.Application.Code;
using LeSoft.Application.Entity;
using LeSoft.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace LeSoft.Application.Web.Areas.FinancialManage.Controllers
{
    [HandleError]
    public class ReceiptFeeController : MvcControllerBase
    {
        //
        // GET: /FinancialManage/ReceiptFee/Index

        private ReceiptFeeBLL bll = new ReceiptFeeBLL();

        #region 视图
        [HttpGet]
        [HandlerAuthorize(PermissionMode.Enforce)]
        [HandlerAction(OperationType.Visit)]
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region 获取数据

        /// <summary>
        /// 获取客户名（+房间名）和房产全名
        /// </summary>
        /// <param name="keyVakue">房产Id</param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAction(OperationType.GetForm, "收款", "GetFeeInfo")]
        public ActionResult GetFeeInfo(string keyValue)
        {
            if (!keyValue.IsEmpty())
            {
                PStructEntity entity = new PStructBLL().GetEntity(keyValue);
                if (!entity.IsEmpty() && entity.Type < 5)
                {
                    return Error("选择客户需要精确到房间！");
                }
                var data = bll.GetRelationPCInfo(keyValue);
                if (!data.IsEmpty())
                {
                    return Content(data);
                }
                else
                {
                    return Error("该房间客户信息不全！");
                }
                
            }
            else
            {
                return Error("未选择房间！");
            }

        }
        #endregion

        #region 保存数据
        [HttpPost]
        [ValidateAntiForgeryToken]
        [AjaxOnly]
        [HandlerAction(OperationType.Create, "收款", "SaveReceiptFee")]
        public ActionResult SaveReceiptFee(string postData)
        {
            List<ReceivableFeeItemsEntity> lst = new List<ReceivableFeeItemsEntity>();
            try
            {
                lst = postData.ToObject<List<ReceivableFeeItemsEntity>>();
                bll.SaveReceiptFeeBill(lst);
                return Success("操作成功！");
            }
            catch (Exception e)
            {
                return Error(e.Message);
                throw;
            }
        }
        #endregion


    }
}
